package com.hcms.admin.controller;

import cn.hutool.core.util.RandomUtil;
import com.hcms.admin.annotation.CheckPermission;
import com.hcms.common.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    IEmailService emailService;

    @GetMapping("/test1")
    @CheckPermission(check = false)
    public void test1() {
        String code = RandomUtil.randomString(6).toUpperCase();
        String buffer = "尊敬的用户：\n" +
                "请在48小时内输入以下代码完成验证：\n" +
                code + "\n" +
                "如您不同意，请忽略此邮件。";
        emailService.sendSimpleMail("574343359@qq.com", "hcms邮箱绑定验证", buffer);
    }

    @GetMapping("/test2")
    @CheckPermission(check = false)
    public void test2() throws MessagingException {
        String code = RandomUtil.randomString(6).toUpperCase();
        String buffer = "<h2>尊敬的用户，您的验证码是：</h2>" +
                "<h2>" + code + "</h2>" +
                "<h2>有效期10分钟</h2>";
        emailService.sendHtmlMail("574343359@qq.com", "hcms邮箱绑定验证", buffer);
    }
}
